package cn.ynrcb.personnelfile.admin.controller;


import cn.hutool.core.convert.Convert;
import cn.ynrcb.personnelfile.admin.dao.BusinessLogDao;
import cn.ynrcb.personnelfile.admin.entity.BusinessLogEntity;
import cn.ynrcb.personnelfile.common.utils.PageUtils;
import cn.ynrcb.personnelfile.common.utils.R;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.DynamicParameter;
import com.github.xiaoymin.knife4j.annotations.DynamicResponseParameters;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Api(value = "整改需求系统系统", tags = {"业务相关=>业务日志相关接口"})
@Controller
@RequestMapping("/admin/log")
public class BusinessLogController {
	@Autowired
	private BusinessLogDao businessLogDao;

	/**
	 * 列表
	 */
	@ApiOperation("管理员获取首页统计数据")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "page", value = "页码", example = "1", required = false),
			@ApiImplicitParam(name = "limit", value = "条数", example = "12", required = false)
	})
	@ApiOperationSupport(
		responses = @DynamicResponseParameters(properties = {
				@DynamicParameter(value = "状态码", name = "code", example = "0"),
				@DynamicParameter(value = "信息", name = "message", example = "success"),
				@DynamicParameter(value = "pageList", name = "page", example = "pageList")
		})
	)
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("admin:log:list")
	public R list(@RequestParam Map<String, Object> params){
		Page<BusinessLogEntity> page = new Page<BusinessLogEntity>(Convert.toLong(params.get("page") + "",1L), Convert.toLong(params.get("limit")+"",12L));
		List<BusinessLogEntity> list = businessLogDao.queryPage(page, params);
		page.setRecords(list);
		PageUtils pageList = new PageUtils((IPage<?>) page);
		return R.ok().put("page", pageList);
	}


}
